Skip to content

fix(agents-md-budget): sum every tracked AGENTS.md against Codex's shared budget - #300

Merged
arjmad merged 3 commits into
mainfrom
fm/firstmate-agentsmd-size-guard-1123
Nov 23, 2026
Merged

arjmad merged 3 commits into
mainfrom
fm/firstmate-agentsmd-size-guard-1123

Conversation

@arjmad

@arjmad arjmad commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Codex's project_doc_max_bytes (32 KiB) is one budget shared by every AGENTS.md from the repo root down to the working folder, and Codex cuts it off with no warning. bin/fm-agents-md-budget.sh already guarded the root file at 30,720 bytes. It now sums the root plus every nested AGENTS.md that git does not ignore (git ls-files --cached --others --exclude-standard), staged or not, so ignored paths such as projects/ stay out. When the sum is over the limit, the message points at AGENTS.md "Maintaining this file" and says to prune, not to raise the limit. AGENTS.md itself is untouched.

before: root AGENTS.md only           -> 28234 / 30720
after:  root + nested tracked chain   -> 28234 / 30720 (1 tracked file today)

Evidence

  • bin/fm-agents-md-budget.sh → ok bytes=28234 limit=30720 budget=32768 margin=2048 headroom=2486.
  • Lowered-limit probe (not committed): --margin 6000 → exit 1, the AGENTS.md chain (1 tracked files ...) is 28234 bytes, 1466 over the 26768-byte limit ...; prune it as AGENTS.md "Maintaining this file" says ...; do not raise the limit.
  • The new test builds a scratch repo with a 600 B root, a tracked 300 B nested file and an ignored 5000 B nested file. It passes at 900/900 and fails at 901, naming the chain and printing the prune message.
  • bin/fm-test-run.sh --near: 2/2 pass. bin/fm-lint.sh clean. bin/fm-fork-decisions.sh check ok.

Merge Danger

Door: two-way
Blast Radius: one fork-only check script and its test, plus a docs/scripts.md row and a fork-patch record. From now on, any nested tracked AGENTS.md counts toward the limit.

Reviewed with sol-loop: 3 rounds, gpt-6.2-sol; 5 fixed (nested-path test selection twice, sync baseline, non-ASCII paths, ls-files exit status); declined as nits: untracked root, --repo caller, full-suite fallback for an unmapped nested AGENTS.md (over-selects, still runs the budget test), escaped control-character paths.

Comment thread bin/fm-agents-md-budget.sh Outdated
else
[ -f "$REPO/AGENTS.md" ] || die "no root AGENTS.md in $REPO" 2
# quotePath=false keeps non-ASCII paths literal so each one is found on disk.
tracked=$(git -C "$REPO" -c core.quotePath=false ls-files -- AGENTS.md '*/AGENTS.md') \

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new nested AGENTS.md that has not been staged yet is not counted, so the local check passes while CI fails once the file is committed. The chain comes from git ls-files, which lists only indexed paths. Codex itself reads any AGENTS.md on disk in the chain, whether or not git tracks it. Fix: also list untracked files that are not ignored (git ls-files --cached --others --exclude-standard -- AGENTS.md '*/AGENTS.md'). That keeps projects/ out and counts a file a worker just created.

Failure scenario: A worker creates docs/AGENTS.md (3 KB) in a worktree whose root AGENTS.md is 28,234 bytes. It runs bin/fm-test-run.sh --near before git add, and the budget test reports ok at bytes=28234. The worker commits and opens the PR, and CI fails at 31,234 bytes, over the 30,720 limit. The local check missed what it exists to catch.

@arjmad

arjmad commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

.agents/skills/firstmate-coding-guidelines/SKILL.md:62: The size-discipline step still says the budget check fails once "the file" crosses the budget. After this PR the check sums the root and every tracked nested AGENTS.md. An agent that follows this step and adds a nested AGENTS.md has no reason to think it uses up the root file's headroom. Fix: say the check fails once the tracked AGENTS.md chain (root plus nested) crosses the budget minus the margin.

Failure scenario: An agent reads this guideline, puts conditional detail into a new subdirectory AGENTS.md to keep the root small, and expects the budget to be unaffected. The summed check then fails, or nearly fails, and the guidance the agent followed did not warn about it.

@arjmad

arjmad commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

Code review: Claude Code /code-review (medium) ran on this diff; each finding is posted inline and was fixed or answered in its thread.
Sol: 3 rounds, gpt-6.2-sol, CHANGES settled - remaining findings declined as nits

@arjmad
arjmad merged commit a131991 into main Nov 23, 2026
64 of 66 checks passed
@arjmad
arjmad deleted the fm/firstmate-agentsmd-size-guard-1123 branch November 23, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant